﻿//===============================================================================
// Microsoft Innovation Centre - Western Europe
// Copyright (c) 2008 Microsoft Corporation. All rights reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.Windows;
using Microsoft.WVB.Framework;
using Microsoft.WVB.Framework.Interfaces;
using Microsoft.WVB.Services;
using Microsoft.WVB.UI;
using Microsoft.WVB.Framework.Entities;
using Microsoft.WVB.Silverlight.Infrastructure;
using Microsoft.Practices.Composite.Events;

namespace Microsoft.WVB
{
    public partial class App : Application
    {
        public App()
        {
            this.Startup += this.Application_Startup;
            this.Exit += this.Application_Exit;
            this.UnhandledException += this.Application_UnhandledException;
            InitializeComponent();
        }

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            InitializeIoC();
            this.RootVisual = new Main();
        }
        private void InitializeIoC()
        {
            //Adds DIContainer and Mediator to resources collection of the current Application.
            IoC.InitializeApplicationResources(Application.Current);

            //Register Services here 
            IDIContainer dic = IoC.CurrentApplicationDIContainer;
            IoC.RegisterInstance<IEventAggregator>(new EventAggregator());

            //TODO: Read values from XML Configuration file (Erik)
            dic.Configuration["UserServices_MembershipPath"] = "http://localhost:8080/Membership.svc";
            dic.Configuration["UserServices_ProfilePath"] = "http://localhost:8080/Profile.svc";
            dic.Configuration["DataService_EPG"] = new Uri("http://localhost:8080/CDNDataService.svc");

            //Services
            dic.Register<IProfileProvider<ProfileInfo>>((c) => new MICProfileProvider(c.GetNamedConfigurationItem<string>("UserServices_ProfilePath")));
            dic.Register<IMembershipProvider<MembershipUser>>((c) => new MICMembershipProvider(c.GetNamedConfigurationItem<string>("UserServices_MembershipPath")));
            dic.Register<AdProvider>((c) => new AtlasService());
            dic.Register<DataFeedService>((c) => new EPGFeedService(c.GetNamedConfigurationItem<Uri>("DataService_EPG"), null));
           
            //UI Models
            dic.Register<IExplorerModel>((c) => new ExplorerModel());
            dic.Register<ILayoutManager>((c) => new LayoutManager());
            dic.Register<MainModel>((c) => new MainModel());
            dic.Register<CarouselModel>((c) => new CarouselModel());
            dic.Register<EPGModel>((c) => new EPGModel());            
            dic.Register<IPlayerModel>((c) => new PlayerModel());
            dic.Register<AdManager>((c) => new AdManager());
            dic.Register<ProgramModel>((c) => new ProgramModel());

            dic.Register<IBroadcasterProvider>((c) => new Microsoft.WVB.Services.MockServices.TestData());
            
            //Singleton User
            dic.Register<IUser>((c) => new User<MembershipUser, ProfileInfo>());
            dic.Register<IUserManager>((c) => new UserManager<MembershipUser, ProfileInfo>());
            dic.CreateStore<IUserManager>();

        }

        private void Application_Exit(object sender, EventArgs e)
        {

        }
        private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
        {

        }
    }
}
